package content;

import java.io.File;

import javax.swing.JComponent;
import javax.swing.JFileChooser;

import content.TxtFilter;

public class FileLoader {
	
	public static File openFile(JComponent attacher){
		final JFileChooser fc = new JFileChooser();
		fc.removeChoosableFileFilter(fc.getFileFilter());
		fc.setFileFilter(new TxtFilter());
		int returnValue = fc.showOpenDialog(attacher);
		if (returnValue == JFileChooser.APPROVE_OPTION){
			return fc.getSelectedFile();
		}
		return null;
	}
	
	public static File writeFile(JComponent attacher){
		final JFileChooser fc = new JFileChooser();
		fc.removeChoosableFileFilter(fc.getFileFilter());
		fc.setFileFilter(new TxtFilter());
		System.out.println("Picking File");
		int returnValue = fc.showSaveDialog(attacher);
		if (returnValue == JFileChooser.APPROVE_OPTION){
			return fc.getSelectedFile();
		}
		return null;
	}
	
}
